package com.adams.dcxt.service;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.adams.dcxt.bean.Dishes;
import com.adams.dcxt.core.Contants;
import com.adams.dcxt.core.Page;
import com.adams.dcxt.dao.DishesDao;

@Service("dishesService")
@Transactional
public class DishesServiceImpl implements DishesService {

    @Autowired
    private DishesDao dishesDao;

    @Override
    public Page<Dishes> queryByType(Page<Dishes> page, Long typeId) {
        Page<Dishes> pageList = dishesDao.queryDishesById(page, typeId);
        return pageList;
    }

    @Override
    public Page<Dishes> queryRecommend(Page<Dishes> page) {
        String hql = " from Dishes where recommendFlag = " + Contants.RECOMMEND;
        Map values = new HashMap();
        return dishesDao.queryPage(page, hql, values);
    }

    @Override
    public Page<Dishes> querySpecialRate(Page<Dishes> page) {
       String hql =" from Dishes where  specialRate <> '1' ";
       Map values = new HashMap();
       return dishesDao.queryPage(page, hql, values);
    }

    @Override
    public Page<Dishes> queryTop(Page<Dishes> page) {
        String hql =" from Dishes order by  buyCount desc";
        Map values = new HashMap();
        return dishesDao.queryPage(page, hql, values);
    }

    @Override
    public Page<Dishes> queryByDishesName (Page<Dishes> page ,String name) {
        String hql =" from Dishes where  dishesName like '%"+name+"%' ";
        return dishesDao.queryPage(page, hql, new HashMap());
    }

    @Override
    public Page<Dishes> queryByDishesIngredients(Page<Dishes> page ,String ingredients) {
        String hql =" from Dishes where  ingredients like '%"+ingredients+"%' ";
        return dishesDao.queryPage(page, hql, new HashMap());
    }

    @Override
    public Dishes get(Long id) {
        return dishesDao.get(id);
    }

	@Override
	public void updateTop(int buyCount ,Long dishedId) {
	String sql= "update  dcxt_dishes set dishes_buy_count=dishes_buy_count+"+buyCount+" where  dishes_id = "+dishedId;
	dishesDao.executeSql(sql);
	}

}
